<!-- 案例详情页面 -->
<link rel="stylesheet" href="/css/apps/microcase/hotDetail.css">
<div class="main layui-clear">
	<div class="wrap layui-clear">
		<div class="layui-left">
			<div class="layui-bar">
				<div class="layui-breadcrumbs">
					<a class="home" href="/"></a>
					<i class="layui-icon">&#xe602;</i>
			  		<a href="/microcase/allList">下载中心</a>
			  		<i class="layui-icon">&#xe602;</i>
			  		<a href="/admin/microcase/hotDetail/${microcase.id!''}.html?id=${microcase.id!''}">${microcase.title!''}</a>
				</div>
			</div>
			<div class="goBack" onclick="window.location.href=document.referrer">
				<i class="layui-icon">&#xe603;</i>  
				<span>返回</span>
			</div>
			<div class="layui-clear content-top">
				<#if microcase.essencecase =="1">
					<span class="tag-tip essence"></span>
	            </#if>
				<h2 class="title layui-elip">${microcase.title!''}</h2>
				<p class="author-time pc-title">
					<span class="author">作者：${microcase.author!''}</span>
					<span>时间：${microcase.releasetime!?string("yyyy-MM-dd")}</span>
				</p>
				<p class="text-center phone-title">
					<span class="user">${microcase.user!''} | ${microcase.releasetime!?string("yyyy-MM-dd")}</span>
					<#if microcase.essencecase =="1">
						<span class="phone-essence">
						</span>
		            </#if>
				</p>
				<div class="layui-clear collect-box">
					<div class="layui-clear left">
						<span class="img"><img alt="" src="/${microcase.filelogourl!''}" onerror="this.src='/images/user/default.jpg';this.onerror=null"></span>
						<div class="collect-price">
							<p class="layui-elip red">￥
								<#if microcase.price?string('')=='0'>
									免费
								<#else>
									${microcase.price?string('0.00')}
								</#if>
								<span class="phone-show">平均评级：<span id="phone-show"></span>分</span>
							</p>
							<p class="micro">
								<span>使用配件:</span>
								<#if dictList??>
									<#list dictList as list>
										<span>${list.label!''}</span>
									</#list>
								</#if>
							</p>
							<div class="collect-btn" onclick="collect('${microcase.id!''}')">
								<input type="hidden" value="${status}" id="status">
								<#if status=="收藏">
									<a href="#"><span class="icon"></span><span class="btn-text">取消</span></a>
								</#if>
								<#if status=="取消">
									<a href="#"><span class="icon un"></span><span class="btn-text">收藏</span></a>
								</#if>
								
							</div>
						</div>
					</div>
					<div class="layui-clear right">
						<div class="grade-left">
							<input type="hidden" id="countavg" value="${microcase.countavg!''}" />
							<span>已有${microcase.commentnums!''}人评价</span>
							<ul>
								<li><span class="icon-start"></span><span class="icon-start"></span><span class="icon-start"></span><span class="icon-start"></span><span class="icon-start"></span></li>
								<li><span class="icon-start"></span><span class="icon-start"></span><span class="icon-start"></span><span class="icon-start"></span></li>
								<li><span class="icon-start"></span><span class="icon-start"></span><span class="icon-start"></span></li>
								<li><span class="icon-start"></span><span class="icon-start"></span></li>
								<li><span class="icon-start"></span></li>
							</ul>
						</div>
						<div class="grade-right">
							<span>&nbsp;&nbsp;/&nbsp;&nbsp;平均&nbsp;</span><span id="countavg-span"></span>
							<ul>
								<li><span class="progress progress-five"></span><span class="num five">0%</span></li>
								<li><span class="progress progress-four"></span><span class="num four">0%</span></li>
								<li><span class="progress progress-three"></span><span class="num three">0%</span></li>
								<li><span class="progress progress-two"></span><span class="num two">0%</span></li>
								<li><span class="progress progress-one"></span><span class="num one">0%</span></li>
							</ul>
						</div>
					</div>
				</div>
			</div>
			<div class="content-main">
				<div id="info" class="waterImg">
					${( microcase.describecontent?replace('<img src=', '<img src="/images/loading2.gif"  lay-src=') )?no_esc}
					
				</div>
				<div class="statistics">
					<span>收藏量&nbsp;&nbsp;(${microcase.collectionnum!0})</span>
				</div>
				<!-- 分享 -->
				<div class="share-box">
					<a  href="#" class="weixin" id="weixin" title="分享到微信" onmouseover='getWinXixImg("${microcase.id!''}","/admin/microcase/hotDetail")'>
						<div class="weixin-box">
							<div class="weixin-img" id="weixin${microcase.id!''}"></div>
							<i class="sprite"></i>
						</div>
					</a>
					<a  href="#" class="weibo" id="weibo${microcase.id!''}"  title="分享到微博" onclick='getXLWBRHerf("/admin/microcase/hotDetail","${microcase.id!''}","${microcase.title!''} - 盒子实验室 BOX LAB")'></a>
					<a  href="#" class="qzone" id="qzone${microcase.id!''}"  title="分享到QQ空间" onclick='getQQRHerf("/admin/microcase/hotDetail","${microcase.id!''}","${microcase.title!''}","针对国内青少年STEAM创客教育建设的，提供教学案例，案例代码，国内外一手资源和创新实验信息等的开源交流社区。")'></a>
				</div>
				
				
				<!-- <#if microcase.price?? && microcase.price?string('')=='0'>
				<#else>
					<a href="/admin/wechatpay/forPay?price=${microcase.price}&microId=${microcase.id}" target="_blank">微信支付</a>
					<a href="/alipay/forPay?WIDtotal_amount=${microcase.price?string('0.0')}&WIDsubject=${microcase.title}&microcaseId=${microcase.id}" target="_blank">支付宝支付</a>

				</#if> -->
				
				<#if user??><!-- 是否登录 -->
					<#if microcase.price?? && microcase.price?string('')=='0'><!-- 免费 -->
					
					<#else>
						<#if user.username != microcase.author >
							<#if downloadPower!=null>
								<div class="pay-box <#if downloadPower=='no_permissions'>layui-show<#elseif downloadPower=='permissions'>layui-hide</#if>">
									<p class="price">￥&nbsp;${microcase.price?string('0.00')}</p>
									<p>支付后可下载</p>
									<p>支付宝扫描二维码</p>
									
								    <button class="layui-btn layui-hide" onclick="onPayFormWX('${microcase.id}','${user.id}')">微信支付</button> 
							        <button  class="layui-btn" onclick="window.location.href='/alipay/forPay?WIDtotal_amount=${microcase.price?string('0.00')}&WIDsubject=${microcase.title}&microcaseId=${microcase.id}'">支付宝支付</button>
						
									<!-- <p><img src="/wechatpay/forPay?microId=${microcase.id}"/></p> -->
									<!-- <p><img src="/admin/alipay/forPay?WIDtotal_amount=${microcase.price?string('0.00')}&WIDsubject=${microcase.title}&microcaseId=${microcase.id}"/></p> -->
								</div>
							</#if>
						</#if>

					</#if>
					<!-- 创建者不需要下载权限，可以直接下载 -->
					<#if user.username == microcase.author >
						<div class="layui-bar <#if (microenclosureList?size)==0>layui-hide</#if>">
							<div class="file-title">附件</div>
						</div>
					<#else>
						<div class="layui-bar <#if (microenclosureList?size)==0>layui-hide</#if> <#if downloadPower=='no_permissions'>layui-hide<#elseif downloadPower=='permissions'>layui-show</#if>">
							<div class="file-title">附件</div>
						</div>
					</#if>
			        <#if user.username == microcase.author >
						<div class="download-list <#if (microenclosureList?size)==0>layui-hide</#if>">
							<ul>
								<#if microenclosureList??>
									<#list microenclosureList as list>
										<li class="file-list">
											<span class="span-img">
											<#assign fileType=list.enclosurename?split('.')[1]>
								      			<#if "png,jpg,gif,jpeg,bmp"?contains(fileType)>
								      				<span class="file-type img"></span>
							      				<#elseif "doc,docx,dotx,xlsx,xlsm,xltx,txt"?contains(fileType)>
							      					<span class="file-type txt"></span>
							      				<#elseif "pdf"?contains(fileType)>
							      					<span class="file-type pdf"></span>
						      					<#elseif "rar,zip"?contains(fileType)>
						      						<span class="file-type rar"></span>
						      					<#else>
						      						<span class="file-type other"></span>
								      			</#if>
											</span>
											<div class="layui-elip">
												<p class="layui-elip">
													<#if user??>
														<a  class="filename layui-elip" href="javascript:" href-link="/admin/microcase/download?id=${list.id!''}" onclick="isDownload(this,'${list.creater}')">${list.enclosurename!''}</a>
									      				<a  class="filename phone-down" href="javascript:" href-link="/admin/microcase/download?id=${list.id!''}" onclick="isDownload(this,'${list.creater}')">下载</a>
									      			<#else>
									      				<a class="filename layui-elip" href="/login.html">${list.enclosurename!''}</a>
									      				<a class="filename phone-down" href="/login.html">下载</a>
									      			</#if>
												</p>
												<span class="filesize">${list.filesize!''}KB</span><span class="download-num">${list.downcount!''}次</span>
											</div>
										</li>
									</#list>
								</#if>
							</ul>
						</div>
					<#else>
						<div class="download-list <#if (microenclosureList?size)==0>layui-hide</#if> <#if downloadPower=='no_permissions'>layui-hide<#elseif downloadPower=='permissions'>layui-show</#if>">
							<ul>
								<#if microenclosureList??>
									<#list microenclosureList as list>
										<li class="file-list">
											<span class="span-img">
											<#assign fileType=list.enclosurename?split('.')[1]>
								      			<#if "png,jpg,gif,jpeg,bmp"?contains(fileType)>
								      				<span class="file-type img"></span>
							      				<#elseif "doc,docx,dotx,xlsx,xlsm,xltx,txt"?contains(fileType)>
							      					<span class="file-type txt"></span>
							      				<#elseif "pdf"?contains(fileType)>
							      					<span class="file-type pdf"></span>
						      					<#elseif "rar,zip"?contains(fileType)>
						      						<span class="file-type rar"></span>
						      					<#else>
						      						<span class="file-type other"></span>
								      			</#if>
											</span>
											<div class="layui-elip">
												<p class="layui-elip">
													<#if user??>
														<a  class="filename layui-elip" href="javascript:" href-link="/admin/microcase/download?id=${list.id!''}" onclick="isDownload(this,'${list.creater}')">${list.enclosurename!''}</a>
														<a  class="filename phone-down" href="javascript:" href-link="/admin/microcase/download?id=${list.id!''}" onclick="isDownload(this,'${list.creater}')">下载</a>
									      			<#else>
									      				<a class="filename layui-elip" href="/login.html">${list.enclosurename!''}</a>
									      				<a class="filename phone-down" href="/login.html">下载</a>
									      			</#if>
												</p>
												<span class="filesize">${list.filesize!''}KB</span><span class="download-num">${list.downcount!''}次</span>
											</div>
										</li>
									</#list>
								</#if>
							</ul>
						</div>
					</#if>
					
					
					
		        <#else>
		        	<ul class="comment-list">
						<li class="none-comment"><a href="/login.html" style="color: #53CAE3;font-weight:bold;">登录</a> 后查看下载详情</li>
					</ul>
		        </#if>
				
				
			</div>
			<div class="content-bottom">
				<div class="layui-bar">
					<div class="layui-breadcrumbs"><span>案例评论</span></div>
				</div>
				<div class="comment-box">
					<ul class="comment-list">
						<#if commentList??>
							<#list commentList.content as list>
								<li>
									<div class="card">
										<span class="img">
											<a href="<#if list.name == user.username>/user/profile.html<#else>/user/otherUser/${list.creater}.html</#if>" <#if list.name != user.username>target="_blank"</#if>>
											<img class="layui-img" alt="" src="/${list.fileurl!''}" onerror="this.src='/images/user/default.jpg';this.onerror=null"></a>
										</span>
										<div class="card-info">
											<p>
												<a  class="name" href="<#if list.name == user.username>/user/profile.html<#else>/user/otherUser/${list.creater}.html</#if>" <#if list.name != user.username>target="_blank"</#if>><span>${list.name!''}</span></a>
												<span class="garde">
													
												<#if list.starlevel == '1'>
													<span class="icon-start"></span>
												<#elseif list.starlevel=='2'>
													<span class="icon-start"></span>
													<span class="icon-start"></span>

												<#elseif list.starlevel=='3'>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
												<#elseif list.starlevel=='4'>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
												<#elseif list.starlevel=='5'>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
													<span class="icon-start"></span>
												<#elseif list.starlevel==''>
													<span class="">暂无评分</span>
												</#if>
											</span>
											<span class="time">${list.commenttime!?string("yyyy-MM-dd HH:mm:ss")}</span>
										</p>
										<p class="layui-elip describecontent">
											${( list.describecontent?replace('<img src=', '<img src="/images/loading2.gif"  lay-src='))?no_esc}
										</p>
									</div>
								</div>
							</li>
						</#list>
						<#if (commentList.content?size)==0>
			        		<li class="none-comment">没有任何回答</li>
			        	</#if>
						</#if>
					</ul>
					<div style="text-align: center" class="front-desk">
						<div class="laypage-main" id="pages"></div>
					</div>
				</div>
			</div>
			<div class="phone-recommend">
				<div class="phone-recommend-case">
					<span>推荐案例</span>
				</div>
				<ul class="phone-recommend-list">
					<#if topmicrocaseList??>
						<#list topmicrocaseList as topmicrocaselist>
							<#if topmicrocaselist_index<5>
								<li>
									<a class="layui-clear" href="/admin/microcase/hotDetail/${topmicrocaselist.id!''}.html?id=${topmicrocaselist.id!''}">
										<div class="card-list">
											<span class="class-info">${topmicrocaselist.title!''}</span>
											<div class="downnums">
												<span>下载量：${topmicrocaselist.downnums!''}</span>
												<!-- <span>案例星级：${topmicrocaselist.countavg!''}</span> -->
											</div>
										</div>
									</a>
								</li>
							</#if>
						</#list>
					</#if>
				</ul>
			</div>
		</div>
		<div class="layui-right">
			<div class="recommend-section">
				<span class="section-line"></span>
				<span class="text"><span class="zh">推荐案例</span><br /><span class="en">RECOMMEND</span></span>
				<span class="section-line line-rotate"></span>
			</div>
			<ul class="recommend-list">
				<#if topmicrocaseList??>
					<#list topmicrocaseList as topmicrocaselist>
						<#if topmicrocaselist_index<5>
							<li>
								<a class="layui-clear" href="/admin/microcase/hotDetail/${topmicrocaselist.id!''}.html?id=${topmicrocaselist.id!''}">
									<div class="card-list">
										<span class="class-info">${topmicrocaselist.title!''}</span>
									</div>
								</a>
							</li>
						</#if>
						
						
					</#list>
				</#if>
			</ul>
			<div class="recommend-section">
				<span class="text"><span class="zh">最近下载</span><br /><span class="en">DOWNLOADED</span></span>
			</div>
			<ul class="downloaded-list">
				<#if downsList??>
					<#list downsList.content as downslist>
						<#if downslist_index<5>
							<li>
								<a class="layui-clear layui-elip" href="<#if downslist.name == user.username>/user/profile.html<#else>/user/otherUser/${downslist.creater}.html</#if>" <#if downslist.name != user.username>target="_blank"</#if>>
									<div class="card-list">
										<span class="class-img"><img alt="" src="/${downslist.fileurl!''}" onerror="this.src='/images/user/default.jpg';this.onerror=null"></span>
										<div class="class-info">
											<span class="name">${downslist.name!''}</span>
											<span class="time" id="${downslist.id!''}"></span>
										</div>
									</div>
								</a>
							</li>
						</#if>
					</#list>
				</#if>
			</ul>
		</div>
	</div>
</div>

<script>
var microcaseList = [],dictList = [],commentList = [],anlist = [],downlist= [],microenclosureList = [];

console.log("收藏状态：status==》","${status}");

<#list microcase as list>
microcaseList.push({"id":"${list.id!''}","title":"${list.title!''}","countavg":"${list.countavg!''}","author":"${list.author!''}","price":"${list.price!''}","filename":"${list.filename!''}","fileurl":"${list.fileurl!''}","evaluate":"${list.evaluate!''}","describecontent":"${list.describecontent!''}","creater":"${list.creater!''}","gradedescribe":"${list.gradedescribe!''}","parts":"${list.parts!''}","releasetime":"${list.releasetime!''}","downnums":"${list.downnums!''}","commentnums":"${list.commentnums!''}","gradename":"${list.gradename!''}"});
</#list>
console.log("案例详情：microcaseList==》",microcaseList);

<#list microenclosureList as list>
microenclosureList.push({"id":"${list.id!''}","enclosurename":"${list.enclosurename!''}","enclosureurl":"${list.enclosureurl!''}","downcount":"${list.downcount!''}","filetype":"${list.filetype!''}"});
</#list>
console.log("附件：microenclosureList==》",microenclosureList);

<#list dictList as list>
dictList.push({"id":"${list.id!''}","label":"${list.label!''}"});
</#list>
console.log("推荐配件：dictList==》",dictList);

<#list commentList.content as list>
commentList.push({"id":"${list.id!''}","name":"${list.name!''}","username":"${list.username!''}","starlevel":"${list.starlevel!''}","commenttime":"${list.commenttime!''}"});
</#list>
console.log("评论列表信息：commentList==》",commentList);

<#list topmicrocaseList as list>
anlist.push({"id":"${list.id!''}","title":"${list.title!''}","downnums":"${list.downnums!''}","evaluate":"${list.evaluate!''}","commenttime":"${list.commenttime!''}"});
</#list>
console.log("推荐案例：anlist==》",anlist);

<#list downsList.content as list>
downlist.push({"id":"${list.id!''}","name":"${list.name!''}","downtime":"${list.downtime!?string("yyyy-MM-dd HH:mm:ss")}","fileurl":"${list.fileurl!''}"});
</#list>
console.log("最近下载：downlist==》",downlist);


layui.use(['form' , 'layedit','laypage', 'layer','flow'], function(){
		var laypage = layui.laypage;
		var form = layui.form() ;
		layedit = layui.layedit;
		var flow = layui.flow;
		  //当你执行这样一个方法时，即对页面中的全部带有lay-src的img元素开启了懒加载（当然你也可以指定相关img）
	  	flow.lazyimg();
	  	laypage({
		    cont: 'pages'
		    ,first:'首页'
		    ,last:'末页'
		    ,pages: ${commentList.totalPages}
		    ,curr:${commentList.number+1}
		    ,skin: '#32c24d'
	    	,skip: true
		    ,jump:function(obj, first){
		    	var curr = obj.curr;
		    	if(!first){
		    		location.href = '/admin/microcase/hotDetail/${microcase.id!''}.html?id=${microcase.id!''}?p='+curr;
		    	}
		    }
		});
});
layui.use(['flow'], function(){
	  var flow = layui.flow;
	  //当你执行这样一个方法时，即对页面中的全部带有lay-src的img元素开启了懒加载（当然你也可以指定相关img）
  	 flow.lazyimg();
});

//图片懒加载之后添加水印
function watermarkLazy(e){
	wmark.init({"path": "/res/configurationFile/${waterImg.imageurl!''}","className":"watermarkLazy" });
}

function collect(id,status){
	$(".collect-btn").attr("onclick","");
	var status = $("#status").val();
	$.ajax({
		type: "POST",
		url: "/admin/microcase/collection/" + id,
		dataType: "text",
		data: {
			status: status
		},
		async: true,
		success: function(data) {
			if(data == "收藏"){
				$(".collect-btn .icon").removeClass("un");
				$(".collect-btn .btn-text").html("取消");
				$("#status").val(data);
				$(".collect-btn").attr("onclick","collect('"+id+"')");
			}else if(data == "取消"){
				$(".collect-btn .icon").addClass("un");
				$(".collect-btn .btn-text").html("收藏");
				$("#status").val(data);
				$(".collect-btn").attr("onclick","collect('"+id+"')");
			}else{
				window.location.href = "/login.html";
			}
		}
	})
}
averageScore();
percent();
function averageScore() {//平均分回显
	var countavg = $("#countavg").val() / 2;
	var phoneCountavg = $("#countavg").val();
	$("#phone-show").html(new Number(phoneCountavg).toFixed(1));
	for(var i=0;i<countavg;i++){
		var $span = '<span class="icon-start"></span>'
		$("#countavg-span").append($span);
    }
	
	if( ( countavg - parseInt(countavg)) > 0){
		$("#countavg-span span:last-child").addClass("half-stars");
	}else if(countavg == 0){
		$("#countavg-span").html("暂无评分");
	}
}
function percent(){//百分比
	
	var headcount = ${starlevels['one']} + ${starlevels['two']} + ${starlevels['three']} + ${starlevels['four']} + ${starlevels['five']};//总人数
	
	var one = (( ${starlevels['one']} / headcount ) * 100).toFixed(0);
	var two = (( ${starlevels['two']} / headcount ) * 100).toFixed(0);
	var three = (( ${starlevels['three']} / headcount ) * 100).toFixed(0);
	var four = (( ${starlevels['four']} / headcount ) * 100).toFixed(0);
	var five = (( ${starlevels['five']} / headcount ) * 100).toFixed(0);

	$(".progress-one").css("width",(isNaN(one)? 0 : one ) +'px');
	$(".progress-two").css("width",(isNaN(two)? 0 : two ) +'px');
	$(".progress-three").css("width",(isNaN(three)? 0 : three ) +'px');
	$(".progress-four").css("width",(isNaN(four)? 0 : four ) +'px');
	$(".progress-five").css("width",(isNaN(five)? 0 : five ) +'px');
	
	$(".one").html((isNaN(one)? 0 : one ) +'%');
	$(".two").html((isNaN(two)? 0 : two ) +'%');
	$(".three").html((isNaN(three)? 0 : three ) +'%');
	$(".four").html((isNaN(four)? 0 : four ) +'%');
	$(".five").html((isNaN(five)? 0 : five ) +'%'); 
}

//计算下载以过时间
timer();
function timer(){
	var currentTime = getNowDate(new Date());
	$.each(downlist,function(index,item){
		var timeJson = DateDiff(item.downtime, currentTime);
		if(timeJson.Days != 0){
			$("#"+item.id).html(timeJson.Days+"天前");
		}else if(timeJson.Hours != 0){
			$("#"+item.id).html(timeJson.Hours+"小时前");
		}else if(timeJson.Minutes != 0){
			$("#"+item.id).html(timeJson.Minutes+"分钟前");
		}else{
			$("#"+item.id).html("刚刚");
		}
	})
}

function DateDiff(sDate1, sDate2) {
	
	var oDate1 = new Date(sDate1.replace(" ", "T")).getTime();
	var oDate2 = new Date(sDate2.replace(" ", "T")).getTime();
	
	var timeSpan = {};
	var TotalMilliseconds = Math.abs(oDate1 - oDate2); //相差的毫秒数
	timeSpan.Days = parseInt(TotalMilliseconds / 1000 / 60 / 60 / 24);//相差的天数
	timeSpan.TotalHours = parseInt(TotalMilliseconds / 1000 / 60 / 60);//相差的小时
	timeSpan.Hours = timeSpan.TotalHours % 24;
	timeSpan.TotalMinutes = parseInt(TotalMilliseconds / 1000 / 60);
	timeSpan.Minutes = timeSpan.TotalMinutes % 60;
	timeSpan.TotalSeconds = parseInt(TotalMilliseconds / 1000);
	timeSpan.Seconds = timeSpan.TotalSeconds % 60;
	timeSpan.TotalMilliseconds = TotalMilliseconds;
	timeSpan.Milliseconds = TotalMilliseconds % 1000;
	return timeSpan;
}

function getNowDate(date) {
	var myDate = new Date(date);
	var year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
	var month = myDate.getMonth(); //获取当前月份(0-11,0代表1月)
	var day = myDate.getDate(); //获取当前日(1-31)
	var hour = myDate.getHours();
	var minute = myDate.getMinutes();
	var second = myDate.getSeconds(); //秒
	var time = formate(year) + "-" + formate(month + 1) + "-" + formate(day) + " " + formate(hour) + ":" + formate(minute) + ":" + formate(second);
	return time;
}

function formate(myDate) {
	return myDate > 9 ? myDate : '0' + myDate;
}

/* QRcode("${microcase.id!''}","${microcase.price!''}");/* 请求微信支付二维码 */
/* function QRcode(id,price){
	$.ajax({
		  type:"POST",
		  url:"/wechatpay/forPay",
		  async:false,
		  data:{microId:id,price:price},
		  success:function(data){
			  $("#pay-weiixn").attr("src","/res/QRupload/"+data+".html") 
		  }
	  })
}   */

/* 
function wecharPay(){
	
	
	
	
	if (typeof WeixinJSBridge == "undefined"){
	   if( document.addEventListener ){
	       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	   }else if (document.attachEvent){
	       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
	       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	   }
	}else{
	   onBridgeReady();
	}   	
}
 */
 var paylayer = false, setpay ,setTime;
 /* 显示验证码 */
function onPayFormWX(id,userId){
	//页面层
	layer.open({
	  type: 1,
	  skin: 'layui-layer-rim', //加上边框
	  title: '微信扫码支付', 
	  area: ['300px', '400px'], //宽高
	  content: '<div class="set-time" style="text-align: center;">请扫码支付</div><img src="/wechatpay/forPay?microId='+id+'">',
	  success :function (){
		  var time= 60;
		  paylayer = true;
		  setpay = setInterval(function(){
			  onBridgeReady(id,userId)
		  },1000);
		  setTime = setInterval(function(){
			  if(time<=0){
				  layer.closeAll();
				  clearInterval(setTime);
				  clearInterval(setpay);
			  }
			  $(".set-time").text(time+"秒后二维码失效" );
			  time--;
		  },1000);
	  },
	  cancel: function(index, layero){ 
		  paylayer = false;
		}    
	});

}

 /* 验证用户是否支付 */
function onBridgeReady(microcaseId,userId){
	console.log("验证用户是否支付");
	$.ajax({
		type: "POST",
		url:"/wechatpay/checkPay",
		async: false,
		data:{microcaseId:microcaseId,userId:userId},
		success: function(data){
			console.log("success data:");
			console.log(data);
			if(data=="success"){
				console.log("清除刷新");
				clearInterval(setpay);
				window.location.reload();
			}
			if(!paylayer){
				console.log("清除");
				clearInterval(setpay);
			}
		},
		error: function(data){
			console.log("验证用户是否支付error");
			console.log(data);
		},
	});
   
} 

//判断积分是否够下载
function isDownload(down,id){
	  $.ajax({
		  type:"POST",
		  url:"/topic/isdownload",
		  async:false,
		  data:{id:id},
		  success:function(data){
			  if(data == "success"){
				  window.location.href  = $(down).attr("href-link");
			  }else{
				  layer.msg('积分不足，快去赚取积分吧', {icon: 2});
			  }
		  }
	  })
	 
}
</script>